package com.trust.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trust.entity.InventoryRecord;
import com.trust.mapper.InventoryRecordMapper;
import com.trust.service.InventoryRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class InventoryRecordServiceImpl extends ServiceImpl<InventoryRecordMapper, InventoryRecord> implements InventoryRecordService {

    @Override
    public List<InventoryRecord> getByCode(String code) {
        LambdaQueryWrapper<InventoryRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryRecord::getCode, code);
        return this.list(wrapper);
    }

    @Override
    public InventoryRecord getByTypeAndParentId(Integer type, Integer parentId) {
        LambdaQueryWrapper<InventoryRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryRecord::getParentId, parentId);
        wrapper.eq(InventoryRecord::getInventoryType, type);
        return this.getOne(wrapper);
    }

    @Override
    public void removeByParentId(Integer parentId) {
        LambdaQueryWrapper<InventoryRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryRecord::getParentId, parentId);
        this.remove(wrapper);
    }
}
